import json


messages = {
    0:"",
    1001:"检测点少于7个",
    1002:"监测点多余7个"
}

class ResponseInfo():
    def __init__(self,target_nodes,coordinate_node,code = 0):
        self.sessionId = ""
        self.success = True
        self.code = code
        self.message = ""
        self.target_nodes = target_nodes
        self.coordinate_node = coordinate_node
        #如果是旧卡，就reverse一下
        self.target_name = ["PH","OA","NAG","PIP","SNA","LE","H2O2"][::-1]
        self.version="v0.1.3"




    def caculate_label(self,use_type,use_fuc):
        for i in self.target_nodes:
            i.get_node_distance(self.coordinate_node)

        self.target_nodes.sort(key=lambda i:i.distiance)
        for label,node in zip(self.target_name,self.target_nodes):
            node.set_label(label)
            #node.get_predict_info_yolo()
            node.get_join_result(use_type,use_fuc)


    def to_json(self):
        output = {}
        output["result"] = {}
        for node in self.target_nodes:
            output["result"].update(node.to_json())

        output["sessionId"] = self.sessionId
        output["code"] = self.code
        output['messgage'] = messages[self.code]
        output['success'] = self.success
        output['version'] = self.version

        return output





